/*
 * server.cpp
 *
 *  Created on: 2013-2-4
 *      Author: tangwu
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "RankServer.h"
#include "TreeArray.h"
/*
 * 对类TreeArray做测试
 */
void testTreeArray(){
	int len=11;
	int* v = new int[len];
	int round=2, test=5, v_max=20;
	srand(time(0));
	for(int i = 0; i < round; i++){
		TreeArray ta(1,1,1,len);
		for(int j = 1; j < len; j++){
			v[j] = rand() % v_max;
			ta.add(j, v[j]);
		}
		fprintf(stdout, "value of array is : \n");
		for(int j = 1; j < len; j++){
			fprintf(stdout, "%d ", v[j]);
		}
		fprintf(stdout, "\n");
		for(int j = 1; j <= test; j++){
			int k = rand()%(len-1);
			k++;
			int s1, s2;
			s1 = s2 = 0;
			for(int g = 1; g <= k; g++){
				s1 += v[g];
			}
			s2 = ta.sum(k);
			fprintf(stdout, "[s1:%d, s2:%d]\n", s1, s2);
			if(s1 != s2){
				fprintf(stderr, "error occur !");
			}
		}
	}
}
int main(int argc, char* argv[]){
	RankServer server("127.0.0.1", 3308, "TreeArray", 100, 35);
	server.listen();
	return 0;
}

